package com.photoeditor.demo.ui.fragement;

import android.app.Activity;
import android.content.ContentResolver;
import android.content.Context;
import android.content.res.Resources;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.constraint.ConstraintLayout;
import android.support.v4.view.ViewConfigurationCompat;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextPaint;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.chad.library.adapter.base.entity.MultiItemEntity;
import com.common.base.utils.DeviceUtils;
import com.photoeditor.R;
import com.photoeditor.demo.app.XFragment;
import com.photoeditor.demo.db.FunctionCardInfoBean;
import com.photoeditor.demo.model.bean.IItemBean;
import com.photoeditor.demo.model.bean.TitleBean;
import com.photoeditor.demo.model.event.SubscribeSuccessEvent;
import com.photoeditor.demo.model.face.FaceConstant;
import com.photoeditor.demo.model.face.report.reportlogic.OneTimeVipHelper;
import com.photoeditor.demo.model.preference.SPDataManager;
import com.photoeditor.demo.model.preference.SpUtils;
import com.photoeditor.demo.model.store.download.DownloadUtils;
import com.photoeditor.demo.model.store.module.BaseOnlineManager;
import com.photoeditor.demo.model.store.module.HomeOnlineManager;
import com.photoeditor.demo.model.store.module.ServerUrlUpdater;
import com.photoeditor.demo.model.store.module.StoreOnlineBean;
import com.photoeditor.demo.model.store.module.StoreOnlineManager;
import com.photoeditor.demo.model.store.module.preload.PreloadManager;
import com.photoeditor.demo.model.subscribe.manager.AppVipManager;
import com.photoeditor.demo.statistics.StatisticsConstant;
import com.photoeditor.demo.statistics.StatisticsUtils;
import com.photoeditor.demo.ui.activity.BabyMainActivity;
import com.photoeditor.demo.ui.activity.GalleryActivity;
import com.photoeditor.demo.ui.activity.edit.EditorImageActivity;
import com.photoeditor.demo.ui.activity.face.FaceLogicActivity;
import com.photoeditor.demo.ui.activity.setting.SettingActivity;
import com.photoeditor.demo.ui.adapter.home.FunctionCardAdapter;
import com.photoeditor.demo.ui.adapter.home.HomeAdapter;
import com.photoeditor.demo.ui.adapter.home.UltraPagerAdapter;
import com.photoeditor.demo.util.AndroidDevice;
import com.photoeditor.demo.util.DisplayUtils;
import com.photoeditor.demo.util.FontUtil;
import com.photoeditor.demo.util.SpaceItemDecoration;
import com.tmall.ultraviewpager.UltraViewPager;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

import static com.photoeditor.demo.ui.activity.GalleryActivity.EXTRA_ENTRANCE;
import static com.photoeditor.demo.ui.activity.face.FaceLogicActivity.REQUEST_CODE_CHOOSE_PHOTO_YOU;
import static com.photoeditor.demo.util.measureTextViewSizeUtils.measureTextView;
import static com.photoeditor.demo.util.measureTextViewSizeUtils.measureTextViewSize;

/**
 * Created by winn on 17/7/12.
 */

public class HomeFragment extends XFragment implements ItemClickSupport.OnItemClickListener, BaseOnlineManager.StoreOnlineListener {

    //mMainButtonEntrance 从主页btn进入其他页面 取值为collage edit ....
    public static final String EXTRA_MAIN_BTN_ENTRANCE = "EXTRA_MAIN_BTN_ENTRANCE";
    public static final String EXTRA_IS_ARTIST = "EXTRA_IS_ARTIST";
    public ArrayList<FunctionCardInfoBean> infos;
    public FunctionCardInfoBean info;
    private Resources resources;
    private Drawable drawable1;
    private Drawable drawable2;
    private Drawable drawable3;



    //    @Bind(R.id.drag_layout)
//    DragLayout mDragLayout;
    @Bind(R.id.list_view)
    RecyclerView mListView;
    @Bind(R.id.error_layout)
    View mErrorLayout;
    @Bind(R.id.editor_tools_entrance)
    ImageView editorToolsEntrance;
//    @Bind(R.id.function_card_recyclerview)
//    RecyclerView functionCardRecyclerview;
//    @Bind(R.id.tv_edit)
//    TextView mEditTextView;
//    @Bind(R.id.tv_camera)
//    TextView mCameraTextView;
//    @Bind(R.id.tv_subscribe)
//    TextView mSubscribeTextView;
    @Bind(R.id.tv_title)
    TextView mTitleTextView;
    @Bind(R.id.ultraViewPager)
    UltraViewPager ultraViewPager;
    @Bind(R.id.face_aging)
    TextView faceAging;
    @Bind(R.id.past_life)
    TextView pastLife;
    @Bind(R.id.gender_swap)
    TextView gendetSwap;
    @Bind(R.id.filter)
    TextView filter;
    @Bind(R.id.baby_prediction)
    TextView babyPrediction;
    @Bind(R.id.stickers)
    TextView stickers;


    private HomeAdapter mHotEffectAdapter;

    private boolean mLoadingRoot = false;

    private ArrayList<MultiItemEntity> mHotEffectDatas;

    //    private FlowAdProvider mAdProvider;
    private boolean mContentItemsReady;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        ViewGroup rootView = (ViewGroup) inflater.inflate(
                R.layout.fragment_home, container, false);
        return rootView;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        ButterKnife.bind(this, view);
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        initView();
//        initTrendingData();
        initHotEffectData();

        //初始化中间的功能卡片的recyclerView
        //initFunctionCardRecyclerView();

        //初始化中间的功能卡片的文字--Face Aging
        measureTextView(getContext(),faceAging,74,109);
        measureTextView(getContext(),gendetSwap,74,109);
        measureTextView(getContext(),pastLife,74,109);
        measureTextView(getContext(),babyPrediction,74,109);
        measureTextView(getContext(),filter,74,109);
        measureTextView(getContext(),stickers,74,109);

        HomeOnlineManager.getInstance().addDataListener(this);
        loadRootModuleData();
        StatisticsUtils.statisticsCustomMainpageShow(StatisticsConstant.UMENG_CUSTOM_EVENT_FUNC_MAINPAGE_FREQUENCY);

        EventBus.getDefault().register(this);

//        FontUtil.setAvenirFontMedium(mEditTextView, mCameraTextView, mSubscribeTextView);
        FontUtil.setCustomFontLobster(mTitleTextView);
    }

    //初始化中间的功能卡片recyclerView
//    private void initFunctionCardRecyclerView() {
//        infos=new ArrayList<>();
//        info=new FunctionCardInfoBean();
//        resources = getActivity().getResources();
//        drawable1= resources.getDrawable(R.drawable.function_card_first);
//        info.setDrawable(drawable1);
//        info.setTitie("Face Aging");
//        infos.add(info);
//
//        info=new FunctionCardInfoBean();
//        drawable2 = resources.getDrawable(R.drawable.function_card_second);
//        info.setDrawable(drawable2);
//        info.setTitie("Past Life");
//        infos.add(info);
//
//        info=new FunctionCardInfoBean();
//        drawable3 = resources.getDrawable(R.drawable.function_card_third);
//        info.setDrawable(drawable3);
//        info.setTitie("Gender Swap");
//        infos.add(info);
//
//
//        FunctionCardAdapter functionCardAdapter=new FunctionCardAdapter(getActivity(),infos);
//        //设置recyclerView的item间隔
//        functionCardRecyclerview.addItemDecoration(new SpaceItemDecoration(-30));
//        functionCardRecyclerview.setLayoutManager(new LinearLayoutManager(getActivity(),LinearLayoutManager.HORIZONTAL,false));
//        functionCardRecyclerview.setAdapter(functionCardAdapter);
//
//        functionCardAdapter.setOnItemClickListener(new FunctionCardAdapter.OnItemClickListener() {
//            @Override
//            public void onItemClicked(View view, int position) {
//                switch (position) {
//                    //Face Aging
//                    case 0: {
//                        StatisticsUtils.statisticGrowingIo(StatisticsConstant.EVENT_MAIN_PAGE_CLICK,
//                                StatisticsConstant.KEY_MAIN_PAGE_FUN, StatisticsConstant.MAIN_PAGE_VALUE_FACE_AGING);
////                        FaceLogicActivity.showReportActivity(getActivity(), FaceConstant.ACTION_FACE_AGING, 0,
////                                FaceConstant.getFaceModelFemale());
//                        Intent intent = new Intent(
//                                Intent.ACTION_PICK,
//                                android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, getActivity(), GalleryActivity.class);
//                        intent.setType("image/*");
//                        intent.putExtra(EXTRA_ENTRANCE, "main_page_aging");
//                        intent.putExtra(HomeFragment.EXTRA_MAIN_BTN_ENTRANCE, "face");
//                        startActivity(intent);
//                        OneTimeVipHelper.getInstance().everyInit();
//                        break;
//                    }
//                    //Past Life
//                    case 1: {
//                        StatisticsUtils.statisticGrowingIo(StatisticsConstant.EVENT_MAIN_PAGE_CLICK,
//                                StatisticsConstant.KEY_MAIN_PAGE_FUN, StatisticsConstant.MAIN_PAGE_VALUE_PAST_LIFE);
//                        Intent intent = new Intent(
//                                Intent.ACTION_PICK,
//                                android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, getActivity(), GalleryActivity.class);
//                        intent.setType("image/*");
//                        intent.putExtra(EXTRA_ENTRANCE, "main_page_past_life");
//                        intent.putExtra(HomeFragment.EXTRA_MAIN_BTN_ENTRANCE, "face");
//                        startActivity(intent);
//                        break;
//                    }
//                    //Geneder Swap
//                    case 2: {
//                        BabyMainActivity.startActivity(getActivity());
////                        StatisticsUtils.statisticGrowingIo(StatisticsConstant.EVENT_MAIN_PAGE_CLICK,
////                                StatisticsConstant.KEY_MAIN_PAGE_FUN, StatisticsConstant.MAIN_PAGE_VALUE_GENDER_SWAP);
////                        Intent intent = new Intent(
////                                Intent.ACTION_PICK,
////                                android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, getActivity(), GalleryActivity.class);
////                        intent.setType("image/*");
////                        intent.putExtra(EXTRA_ENTRANCE, "main_page_gender_swap");
////                        intent.putExtra(HomeFragment.EXTRA_MAIN_BTN_ENTRANCE, "face");
////                        startActivity(intent);
////                        OneTimeVipHelper.getInstance().everyInit();
//                        break;
//                    }
//                }
//            }
//        });
//
//    }


    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);

    }

    @Override
    public void onDetach() {
        super.onDetach();

    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        HomeOnlineManager.getInstance().removeListener(this);
        EventBus.getDefault().unregister(this);
    }

    /**
     * 加载根结点数据
     */
    private void loadRootModuleData() {
        if (!mLoadingRoot) {
            mLoadingRoot = true;
            HomeOnlineManager.getInstance().loadData();
            // 无网络进入后，重新加载数据时，同时加载商店数据，防止模板商店跟主页数据不一致，或模板选择栏点更多无数据
            StoreOnlineManager.getInstance().loadData();
        }
        initRootBean();
        // EntranceAdapter中第一行会有50延时的动画，如果广告插入在第一行可能会出现第二行特效不显示的问题
        // 重现：广告配置插入第一行，进入主页不滚动，取到广告后退出(此时广告没有显示完全不算展示，退出不会销毁)，
        //      再次进入主页，滚动到第二行观察不显示。非必现，但是出现几率很高
//        ThreadPool.runUITask(new Runnable() {
//            @Override
//            public void run() {
//                loadFlowAd();
//            }
//        }, 50);

    }

    @Override
    public void onResume() {
        super.onResume();


        SPDataManager.setAdOneTimeVip(false);
        SpUtils.obtain().save("isFunctionFilter", false);

        checkAdValid();

        ServerUrlUpdater.getInstance().getNewestServerUrl();

        if (mHotEffectAdapter != null) {
            mHotEffectAdapter.setVip(AppVipManager.isVip());
            mHotEffectAdapter.notifyDataSetChanged();
        }

        SPDataManager.setEnterMainPageBefore();

//        if (mDragLayout.getStatus() == DragLayout.Status.Open) {
////            StatisticsUtils.statisticGrowingIo(StatisticsConstant.EVENT_MAIN_PAGE_SHOW, StatisticsConstant.KEY_MAIN_PAGE_FUN,
////                    StatisticsConstant.MAIN_PAGE_VALUE_EDIT);
////            StatisticsUtils.statisticGrowingIo(StatisticsConstant.EVENT_MAIN_PAGE_SHOW, StatisticsConstant.KEY_MAIN_PAGE_FUN,
////                    StatisticsConstant.MAIN_BTN_EFFECT);
////            StatisticsUtils.statisticGrowingIo(StatisticsConstant.EVENT_MAIN_PAGE_SHOW, StatisticsConstant.KEY_MAIN_PAGE_FUN,
////                    StatisticsConstant.MAIN_BTN_ADJUST);
////            StatisticsUtils.statisticGrowingIo(StatisticsConstant.EVENT_MAIN_PAGE_SHOW, StatisticsConstant.KEY_MAIN_PAGE_FUN,
////                    StatisticsConstant.MAIN_PAGE_VALUE_FACE_AGING);
////            StatisticsUtils.statisticGrowingIo(StatisticsConstant.EVENT_MAIN_PAGE_SHOW, StatisticsConstant.KEY_MAIN_PAGE_FUN,
////                    StatisticsConstant.MAIN_PAGE_VALUE_ARTISTIC);
////            StatisticsUtils.statisticGrowingIo(StatisticsConstant.EVENT_MAIN_PAGE_SHOW, StatisticsConstant.KEY_MAIN_PAGE_FUN,
////                    StatisticsConstant.MAIN_PAGE_VALUE_GENDER_SWAP);
////            StatisticsUtils.statisticGrowingIo(StatisticsConstant.EVENT_MAIN_PAGE_SHOW, StatisticsConstant.PROPERTY_KEY_IF_SUB,
////                    AppVipManager.isVip() ? StatisticsConstant.PROPERTY_VALUE_SUB : StatisticsConstant.PROPERTY_VALUE_UNSUB);
//            StatisticsUtils.statisticGrowingIo(StatisticsConstant.EVENT_MAIN_PAGE_SHOW,
//                    StatisticsConstant.PROPERTY_KEY_IF_SUB, AppVipManager.isVip() ? StatisticsConstant.PROPERTY_VALUE_SUB : StatisticsConstant.PROPERTY_VALUE_UNSUB,
//                    StatisticsConstant.KEY_MAIN_PAGE_FUN, StatisticsConstant.MAIN_PAGE_VALUE_EDIT,
//                    StatisticsConstant.KEY_MAIN_PAGE_FUN, StatisticsConstant.MAIN_BTN_EFFECT,
//                    StatisticsConstant.KEY_MAIN_PAGE_FUN, StatisticsConstant.MAIN_BTN_ADJUST,
//                    StatisticsConstant.KEY_MAIN_PAGE_FUN, StatisticsConstant.MAIN_PAGE_VALUE_FACE_AGING,
//                    StatisticsConstant.KEY_MAIN_PAGE_FUN, StatisticsConstant.MAIN_PAGE_VALUE_ARTISTIC,
//                    StatisticsConstant.KEY_MAIN_PAGE_FUN, StatisticsConstant.MAIN_PAGE_VALUE_GENDER_SWAP
//            );
//        }


//        if (AppVipManager.isVip()) {
//            mSubscribeTextView.setText(R.string.entrance_beauty);
//        } else {
//            mSubscribeTextView.setText(R.string.entrance_subscribe);
//        }

        ultraViewPager.setAutoScroll(2500);
    }

    @Override
    public void onPause() {
        super.onPause();

        ultraViewPager.disableAutoScroll();
    }

    @Override
    public void onStop() {
        super.onStop();
        // 切出主页后再次检查是否需要更新预加载数据，提高预加载成功率
        PreloadManager.getInstance().preloadData();
    }

    @Override
    public void needUpdateData(boolean needUpdate) {
        mLoadingRoot = false;
        if (needUpdate) {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    try {
                        initRootBean();
                    } catch (Exception e) {
                    }
                }
            });
        } else {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    List<StoreOnlineBean> data = HomeOnlineManager.getInstance().getDataBean();
                    if ((data == null || data.size() == 0) && !AndroidDevice.isNetworkOK(getContext())) {
                        mErrorLayout.setVisibility(View.VISIBLE);
                    } else {
                        mErrorLayout.setVisibility(View.GONE);
                    }
                }
            });
        }
    }

    private void initRootBean() {
        List<MultiItemEntity> adapterData = mHotEffectAdapter.getData();
//        List<AdItemBean> adItemBeans = new ArrayList<>();
//        if (adapterData != null && !adapterData.isEmpty()) {
//            for (MultiItemEntity entity :
//                    adapterData) {
//                if (entity instanceof AdItemBean) {
//                    adItemBeans.add((AdItemBean) entity);
//                }
//            }
//        }

        //Hot Effects数据
        List<StoreOnlineBean> data = HomeOnlineManager.getInstance().getDataBean();
        mHotEffectDatas = new ArrayList<>();
        if (data != null && data.size() > 0) {
            mErrorLayout.setVisibility(View.GONE);
            mListView.setVisibility(View.VISIBLE);
        } else {
            mErrorLayout.setVisibility(View.VISIBLE);
            mListView.setVisibility(View.GONE);
            mContentItemsReady = false;
            return;
        }
        mContentItemsReady = true;
        for (StoreOnlineBean storeOnlineBean : data) {
            if (storeOnlineBean.getChildModules() != null && storeOnlineBean.getChildModules().size() > 0) {
                mHotEffectDatas.addAll(storeOnlineBean.getChildModules().get(0).getChildModules());
            }
        }

        //加载标题
        TitleBean titleBean1 = new TitleBean(getString(R.string.title_hot_effects));
        mHotEffectDatas.add(/*1*/0, titleBean1);
        mHotEffectDatas.add(1, mHotEffectDatas.get(1));//add comingSoon item

        if (adapterData != null) {
            adapterData.clear();
        }
//        if (mAdProvider != null && !adItemBeans.isEmpty()) {
//            mAdProvider.insertAd(mHotEffectDatas, adItemBeans);
//        }
        mHotEffectAdapter.addData(mHotEffectDatas);
    }

    private void initView() {
        mListView.addOnScrollListener(new RecyclerView.OnScrollListener() {

            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);
//                if (mDragLayout == null) {
//                    return;
//                }
//                if (dy > 0 && recyclerView.canScrollVertically(1)) {
//                    mDragLayout.setCanDrag(false);
//                    mDragLayout.setIsTop(false);
//                } else if (dy < 0 && recyclerView.canScrollVertically(-1)) {
//                    mDragLayout.setCanDrag(false);
//                    mDragLayout.setIsTop(false);
//                } else if (!recyclerView.canScrollVertically(1)) {
//                    mDragLayout.setCanDrag(true);
//                } else if (!recyclerView.canScrollVertically(-1)) {
//                    mDragLayout.setCanDrag(true);
//                    mDragLayout.setIsTop(true);
//                }
            }

        });
//        float itemWidth = ((float) DeviceUtils.getScreenWidthPx() - DeviceUtils.dip2px(18) * 2) / 3;
//        ViewGroup.LayoutParams editLayoutParams = mEditTextView.getLayoutParams();
//        editLayoutParams.width = (int) itemWidth;
//        editLayoutParams.height = editLayoutParams.width;
//        mEditTextView.setLayoutParams(editLayoutParams);
//
//        ViewGroup.LayoutParams cameraLayoutParams = mCameraTextView.getLayoutParams();
//        cameraLayoutParams.width = (int) itemWidth;
//        cameraLayoutParams.height = cameraLayoutParams.width;
//        mCameraTextView.setLayoutParams(cameraLayoutParams);
//
//        ViewGroup.LayoutParams subscribeLayoutParams = mSubscribeTextView.getLayoutParams();
//        subscribeLayoutParams.width = (int) itemWidth;
//        subscribeLayoutParams.height = subscribeLayoutParams.width;
//        mSubscribeTextView.setLayoutParams(subscribeLayoutParams);


//        RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) mEntranceLayout.getLayoutParams();
//        float blank = (float)(DeviceUtils.getScreenWidthPx() - DeviceUtils.dip2px(96) * 3) / 4 - DeviceUtils.dip2px(11);
//        layoutParams.width = (int) (DeviceUtils.getScreenWidthPx() - blank * 2);
//        layoutParams.leftMargin = (int) blank;
//        layoutParams.rightMargin = (int) blank;
//        mEntranceLayout.setLayoutParams(layoutParams);
//        mFScrollView.setRecyclerView(mHotEffectListView);


//        mDragLayout.setDragListener(new DragLayout.DragListener() {
//            @Override
//            public void onOpen() {
//                ultraViewPager.setAutoScroll(2500);
//            }
//
//            @Override
//            public void onClose() {
//            }
//
//            @Override
//            public void onDrag(float percent) {
//                ultraViewPager.disableAutoScroll();//list上下滑动时轮播图会变空白，禁止轮播
//            }
//        });

        initBanner();

        StatisticsUtils.statisticGrowingIo(StatisticsConstant.EVENT_MAIN_PAGE_SHOW,
                StatisticsConstant.PROPERTY_KEY_IF_SUB, AppVipManager.isVip() ? StatisticsConstant.PROPERTY_VALUE_SUB : StatisticsConstant.PROPERTY_VALUE_UNSUB,
                StatisticsConstant.KEY_MAIN_PAGE_FUN, StatisticsConstant.STATISTIC_EVENT_VALUE_FACE_AGING);
        StatisticsUtils.statisticGrowingIo(StatisticsConstant.EVENT_MAIN_PAGE_SHOW,
                StatisticsConstant.PROPERTY_KEY_IF_SUB, AppVipManager.isVip() ? StatisticsConstant.PROPERTY_VALUE_SUB : StatisticsConstant.PROPERTY_VALUE_UNSUB,
                StatisticsConstant.KEY_MAIN_PAGE_FUN, StatisticsConstant.STATISTIC_EVENT_FUN_VALUE_GENDER_SWITCH);

        StatisticsUtils.statisticGrowingIo(StatisticsConstant.EVENT_MAIN_PAGE_SHOW,
                StatisticsConstant.PROPERTY_KEY_IF_SUB, AppVipManager.isVip() ? StatisticsConstant.PROPERTY_VALUE_SUB : StatisticsConstant.PROPERTY_VALUE_UNSUB,
                StatisticsConstant.KEY_MAIN_PAGE_FUN, StatisticsConstant.STATISTIC_EVENT_FUN_VALUE_PAST_LIFE);

        StatisticsUtils.statisticGrowingIo(StatisticsConstant.EVENT_MAIN_PAGE_SHOW,
                StatisticsConstant.PROPERTY_KEY_IF_SUB, AppVipManager.isVip() ? StatisticsConstant.PROPERTY_VALUE_SUB : StatisticsConstant.PROPERTY_VALUE_UNSUB,
                StatisticsConstant.KEY_MAIN_PAGE_FUN, StatisticsConstant.STATISTIC_EVENT_FUN_VALUE_EDIT);

    }

    private void initBanner() {
//        bgaBanner.setData(localImageSize, ImageView.ScaleType.CENTER_CROP,
//                R.drawable.img_banner_1,
//                R.drawable.img_banner_1,
//                R.drawable.img_banner_1);
//        //
//        bgaBanner.setDelegate(new BGABanner.Delegate<ImageView, String>() {
//            @Override
//            public void onBannerItemClick(BGABanner banner, ImageView itemView, String model, int position) {
////                Toast.makeText(banner.getContext(), "点击了" + position, Toast.LENGTH_SHORT).show();
//                gotoTrending(position);
//            }
//        });
//        bgaBanner.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
//            @Override
//            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
//                TextView textView = findViewById(R.id.tvPage);
//                textView.setText(position+1+"/"+bgaBanner.getItemCount());
//                TextView tvName = findViewById(R.id.tvName);
//                switch (position){
//                    case 0:
//                        tvName.setText("Artistic\nFilter");
//                        break;
//                    case 1:
//                        tvName.setText("Aging\nEffect");
//                        break;
//                    case 2:
//                        tvName.setText("Gender\nSwap");
//                        break;
//                }
//            }
//
//            @Override
//            public void onPageSelected(int position) {
//
//            }
//
//            @Override
//            public void onPageScrollStateChanged(int state) {
//
//            }
//        });
//        //
//        findViewById(R.id.tvTry).setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                gotoTrending(bgaBanner.getCurrentItem());
//            }
//        });

//        UltraViewPager ultraViewPager = (UltraViewPager)findViewById(R.id.ultra_viewpager);
        ultraViewPager.setScrollMode(UltraViewPager.ScrollMode.HORIZONTAL);
//initialize UltraPagerAdapter，and add child view to UltraViewPager
        UltraPagerAdapter adapter = new UltraPagerAdapter(false, true);
        ultraViewPager.setAdapter(adapter);
        //try点击事件
        adapter.setItemViewClick(new UltraPagerAdapter.ItemViewClick() {
            @Override
            public void tryClick(int pos) {
                gotoTrending(pos);
            }
        });

//initialize built-in indicator
        ultraViewPager.initIndicator();
        ultraViewPager.getIndicator().setMargin(0, 0, 0, DisplayUtils.dp2px(6));
//set style of indicators
        ultraViewPager.getIndicator()
                .setOrientation(UltraViewPager.Orientation.HORIZONTAL)
                .setFocusColor(Color.WHITE)
                .setNormalColor(Color.parseColor("#66ffffff"))
                .setRadius((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 3, getResources().getDisplayMetrics()));
//set the alignment
        ultraViewPager.getIndicator().setGravity(Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM);
//construct built-in indicator, and add it to  UltraViewPager
        ultraViewPager.getIndicator().build();

//set an infinite loop
        ultraViewPager.setInfiniteLoop(true);
//enable auto-scroll mode
        ultraViewPager.setAutoScroll(2500);


        final ViewPager viewPager = ultraViewPager.getViewPager();
//        setViewPagerScroller(viewPager);
        //viewPager点击事件
        viewPager.setOnTouchListener(new View.OnTouchListener() {
            int touchFlag = 0;
            float x = 0, y = 0;
            ViewConfiguration configuration = ViewConfiguration.get(getActivity());
            int mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                switch (event.getAction()) {
                    case MotionEvent.ACTION_DOWN:
                        touchFlag = 0;
                        x = event.getX();
                        y = event.getY();
                        break;
                    case MotionEvent.ACTION_MOVE:
                        float xDiff = Math.abs(event.getX() - x);
                        float yDiff = Math.abs(event.getY() - y);
                        if (xDiff < mTouchSlop && xDiff >= yDiff)
                            touchFlag = 0;
                        else
                            touchFlag = -1;
                        break;
                    case MotionEvent.ACTION_UP:
                        if (touchFlag == 0) {
                            int currentItem = viewPager.getCurrentItem();
                            gotoTrending(currentItem);
                        }
                        break;
                }
                return false;
            }
        });

        StatisticsUtils.statisticGrowingIo(StatisticsConstant.EVENT_MAIN_PAGE_SHOW,
                StatisticsConstant.PROPERTY_KEY_IF_SUB, AppVipManager.isVip() ? StatisticsConstant.PROPERTY_VALUE_SUB : StatisticsConstant.PROPERTY_VALUE_UNSUB,
                StatisticsConstant.KEY_MAIN_PAGE_FUN, StatisticsConstant.MAIN_PAGE_VALUE_ARTISTIC);

    }

    //设置viewpager滑动时间+速度
//    private void setViewPagerScroller(ViewPager viewPager) {
//        try {
//            Field scrollerField = ViewPager.class.getDeclaredField("mScroller");
//            scrollerField.setAccessible(true);
//            Field interpolator = ViewPager.class.getDeclaredField("sInterpolator");
//            interpolator.setAccessible(true);
//
//            Scroller scroller = new Scroller(getActivity(), (Interpolator) interpolator.get(null)) {
//                @Override
//                public void startScroll(int startX, int startY, int dx, int dy, int duration) {
////                    Log.e("tag", "duration: "+duration);
//                    super.startScroll(startX, startY, dx, dy, /*duration * 7*/1500);    // 这里是关键，将duration变长或变短(duration=200)
//                }
//            };
//            scrollerField.set(viewPager, scroller);
//        } catch (NoSuchFieldException e) {
//            // Do nothing.
//        } catch (IllegalAccessException e) {
//            // Do nothing.
//        }
//    }

    private void gotoTrending(int position) {
//        switch (position) {
//            case ITEM_AGING:
//                StatisticsUtils.statisticGrowingIo(StatisticsConstant.EVENT_MAIN_PAGE_SHOW, StatisticsConstant.KEY_MAIN_PAGE_FUN,
//                        StatisticsConstant.MAIN_PAGE_VALUE_FACE_AGING);
//                break;
//            case ITEM_ARTISTICT:
//                StatisticsUtils.statisticGrowingIo(StatisticsConstant.EVENT_MAIN_PAGE_SHOW, StatisticsConstant.KEY_MAIN_PAGE_FUN,
//                        StatisticsConstant.MAIN_PAGE_VALUE_ARTISTIC);
//                break;
//            case ITEM_GENDER_SWAP:
//                StatisticsUtils.statisticGrowingIo(StatisticsConstant.EVENT_MAIN_PAGE_SHOW, StatisticsConstant.KEY_MAIN_PAGE_FUN,
//                        StatisticsConstant.MAIN_PAGE_VALUE_GENDER_SWAP);
//                break;
//            case ITEM_FACE_SWAP:
//                StatisticsUtils.statisticGrowingIo(StatisticsConstant.EVENT_MAIN_PAGE_SHOW, StatisticsConstant.KEY_MAIN_PAGE_FUN,
//                        StatisticsConstant.MAIN_PAGE_VALUE_FACE_SWAP);
//                break;
//            default:
//                break;
//        }
        switch (position) {
            case /*TrendingAdapter.ITEM_AGING*/ 1: {
//                FaceLogicActivity.showReportActivity(getActivity(), FaceConstant.ACTION_FACE_AGING, 0,
//                        FaceConstant.getFaceModelFemale());
                //改为先跳转到相册
                Intent intent = new Intent(
                        Intent.ACTION_PICK,
                        android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, getActivity(), GalleryActivity.class);
                intent.setType("image/*");
                intent.putExtra(EXTRA_ENTRANCE, "main_page_aging");
                intent.putExtra(HomeFragment.EXTRA_MAIN_BTN_ENTRANCE, "face");
                startActivity(intent);
                OneTimeVipHelper.getInstance().everyInit();
                break;
            }
            case /*TrendingAdapter.ITEM_ARTISTICT*/ 0: {
                // TODO: 2019/4/12 跳转变性
                Intent intent = new Intent(
                        Intent.ACTION_PICK,
                        android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, getActivity(), GalleryActivity.class);
                intent.setType("image/*");
                intent.putExtra(EXTRA_ENTRANCE, "main_page_gender_swap");
                intent.putExtra(HomeFragment.EXTRA_MAIN_BTN_ENTRANCE, "face");
                startActivity(intent);
                OneTimeVipHelper.getInstance().everyInit();
                break;
            }
            case /*TrendingAdapter.ITEM_GENDER_SWAP*/ 2: {
                // TODO: 2019/4/12 跳转艺术滤镜

                GalleryActivity.startGallerySelectEditImagesForArtist(getContext(), StatisticsConstant.MAIN_BTN_EDIT, true);
                SPDataManager.setFunctionEntrance(StatisticsConstant.MAIN_BTN_EDIT);
                StatisticsUtils.statisticGrowingIo(StatisticsConstant.EVENT_MAIN_PAGE_CLICK,
                        StatisticsConstant.PROPERTY_KEY_IF_SUB, AppVipManager.isVip() ? StatisticsConstant.PROPERTY_VALUE_SUB : StatisticsConstant.PROPERTY_VALUE_UNSUB,
                        StatisticsConstant.KEY_MAIN_PAGE_FUN, StatisticsConstant.MAIN_PAGE_VALUE_ARTISTIC);
                break;


            }
            case /*TrendingAdapter.ITEM_FACE_SWAP*/ 3: {
                // TODO: 2019/4/12 跳转前世今生
                Intent intent = new Intent(
                        Intent.ACTION_PICK,
                        android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, getActivity(), GalleryActivity.class);
                intent.setType("image/*");
                intent.putExtra(EXTRA_ENTRANCE, "main_page_past_life");
                intent.putExtra(HomeFragment.EXTRA_MAIN_BTN_ENTRANCE, "face");
                startActivity(intent);
                break;
            }
            default:
                break;
        }
    }

    private void initHotEffectData() {
        // 初始化整个列表
        mHotEffectAdapter = new HomeAdapter(getActivity());
        mListView.setAdapter(mHotEffectAdapter);
        mListView.setHasFixedSize(true);
        mListView.setNestedScrollingEnabled(false);
        ItemClickSupport itemClickSupport = new ItemClickSupport(mListView, mHotEffectAdapter, this);
        mHotEffectAdapter.setItemClickSupport(itemClickSupport);
        GridLayoutManager gridLayoutManager = new GridLayoutManager(getContext(), 2);
        gridLayoutManager.setOrientation(GridLayoutManager.VERTICAL);
        gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
            @Override
            public int getSpanSize(int position) {
                if (mHotEffectDatas.size() > 0 && mHotEffectDatas.get(position).getItemType() == HomeAdapter.TYPE_BASE_ITEM) {
                    return 1;
                } else {
                    return 2;
                }
            }
        });
        mListView.setLayoutManager(gridLayoutManager);
        mListView.addItemDecoration(new RecyclerView.ItemDecoration() {
            int position = -1;

            @Override
            public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
                float offset_outer_dp = 11f;
                float offset_inside_dp = 0f;
                int childPosition = parent.getChildPosition(view);
                if (mHotEffectDatas.size() > 0 && mHotEffectDatas.get(childPosition).getItemType() == HomeAdapter.TYPE_BASE_ITEM) {
//                    if (childPosition >= mBaseItemPosition && childPosition % 2 == 0) {
//                        outRect.left = DeviceUtils.dip2px(12.5f);
//                    } else if (childPosition >= mBaseItemPosition && childPosition % 2 != 0) {
//                        outRect.right = DeviceUtils.dip2px(12.5f);
//                    }
                    if (position == -1) position = 0;
                    else position++;
                    if (position % 2 == 0) {
                        outRect.set(DeviceUtils.dip2px(offset_outer_dp), 0, DeviceUtils.dip2px(offset_inside_dp), DeviceUtils.dip2px(15));
                    } else {
                        outRect.set(DeviceUtils.dip2px(offset_inside_dp), 0, DeviceUtils.dip2px(offset_outer_dp), DeviceUtils.dip2px(15));
                    }
                } else if (mHotEffectDatas.size() > 0 && mHotEffectDatas.get(childPosition).getItemType() == IItemBean.TYPE_AD) {
                    position = -1;//重置BASE_ITEM的position
                    outRect.left = DeviceUtils.dip2px(offset_outer_dp);
                    outRect.right = DeviceUtils.dip2px(offset_outer_dp);
//                    outRect.bottom = DeviceUtils.dip2px(20f);
                } else {
                    position = -1;
//                    outRect.bottom = DeviceUtils.dip2px(5);
                }
            }
        });
//        mListView.addItemDecoration(new CommonItemDecoration(DeviceUtils.dip2px(27), 18/2));
    }

    public void refreshDatas() {
        List<MultiItemEntity> data = mHotEffectAdapter.getData();
        if (data != null) {
            data.clear();
        }
        data.addAll(mHotEffectDatas);
        mHotEffectAdapter.notifyDataSetChanged();
    }

    private boolean checkNeedInitReward() {
        return false;
    }

    @OnClick(R.id.retry_btn)
    void onRetryBtnClick(View v) {
        loadRootModuleData();
    }

    @OnClick(R.id.home_function_aging)
    void onFunctionAgingClick(View v) {
        StatisticsUtils.statisticGrowingIo(StatisticsConstant.EVENT_MAIN_PAGE_CLICK,
                                StatisticsConstant.KEY_MAIN_PAGE_FUN, StatisticsConstant.MAIN_PAGE_VALUE_FACE_AGING);
                        Intent intent = new Intent(
                                Intent.ACTION_PICK,
                                android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, getActivity(), GalleryActivity.class);
                        intent.setType("image/*");
                        intent.putExtra(EXTRA_ENTRANCE, "main_page_aging");
                        intent.putExtra(HomeFragment.EXTRA_MAIN_BTN_ENTRANCE, "face");
                        startActivity(intent);
                        OneTimeVipHelper.getInstance().everyInit();
    }
    @OnClick(R.id.home_function_gender)
    void onFunctionGenderClick(View v) {

        StatisticsUtils.statisticGrowingIo(StatisticsConstant.EVENT_MAIN_PAGE_CLICK,
                StatisticsConstant.KEY_MAIN_PAGE_FUN, StatisticsConstant.MAIN_PAGE_VALUE_GENDER_SWAP);
        Intent intent = new Intent(
                Intent.ACTION_PICK,
                android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, getActivity(), GalleryActivity.class);
        intent.setType("image/*");
        intent.putExtra(EXTRA_ENTRANCE, "main_page_gender_swap");
        intent.putExtra(HomeFragment.EXTRA_MAIN_BTN_ENTRANCE, "face");
        startActivity(intent);
        OneTimeVipHelper.getInstance().everyInit();

    }
    @OnClick(R.id.home_function_past)
    void onFunctionPastClick(View v) {
        StatisticsUtils.statisticGrowingIo(StatisticsConstant.EVENT_MAIN_PAGE_CLICK,
                StatisticsConstant.KEY_MAIN_PAGE_FUN, StatisticsConstant.MAIN_PAGE_VALUE_PAST_LIFE);
        Intent intent = new Intent(
                Intent.ACTION_PICK,
                android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, getActivity(), GalleryActivity.class);
        intent.setType("image/*");
        intent.putExtra(EXTRA_ENTRANCE, "main_page_past_life");
        intent.putExtra(HomeFragment.EXTRA_MAIN_BTN_ENTRANCE, "face");
        startActivity(intent);

    }
    @OnClick(R.id.home_function_filter)
    void onFunctionFilterClick(View v) {
        SpUtils.obtain().save("isFunctionFilter", true);
        GalleryActivity.startGallerySelectEditImagesForArtist(getContext(), StatisticsConstant.MAIN_BTN_EDIT, true);
        SPDataManager.setFunctionEntrance(StatisticsConstant.MAIN_BTN_EDIT);
        StatisticsUtils.statisticGrowingIo(StatisticsConstant.EVENT_MAIN_PAGE_CLICK,
                StatisticsConstant.PROPERTY_KEY_IF_SUB, AppVipManager.isVip() ? StatisticsConstant.PROPERTY_VALUE_SUB : StatisticsConstant.PROPERTY_VALUE_UNSUB,
                StatisticsConstant.KEY_MAIN_PAGE_FUN, StatisticsConstant.MAIN_PAGE_VALUE_ARTISTIC);
    }
    @OnClick(R.id.home_function_baby)
    void onFunctionBabyClick(View v) {
        BabyMainActivity.startActivity(getActivity());
    }
    @OnClick(R.id.home_function_stickers)
    void onFunctionStickersClick(View v) {
        GalleryActivity.startGallerySelectEditImagesForSticker(getActivity(), StatisticsConstant.MAIN_BTN_SWAP);
    }


    @Override
    public void onItemClick(RecyclerView recyclerView, View view, int position, long id) {

    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        destoryFlowAd();
    }

    private boolean isAllDataLoaded() {
        return mContentItemsReady;
    }

    private void loadFlowAd() {
//        if (!AndroidDevice.isNetworkOK(ComponentContext.getContext())) {
//            AdProvider.statisticsNoRequestAd(FlowAdProvider.STATISTICS_NAME, AdProvider.REASON_NETWORK_ERROR);
//            return;
//        }
//        if (mAdProvider == null) {
//            mAdProvider = FlowAdProvider.newProvider("store_flow", AdKeyConstant.AdKeyPlacementID.PLACEMENTID_NATIVE_STORE_WATERFALL_FLOW, -1);
//            mAdProvider.setAdListener(new AdProvider.OnAdListener() {
//
//                @Override
//                public void onAdLoadFinish(String cacheKey) {
//                    if (mAdProvider == null) {
//                        AdProvider.statisticsNoShowAd(FlowAdProvider.STATISTICS_NAME, AdProvider.REASON_PAGE_NO_SHOWING);
//                        return;
//                    }
//                    mAdProvider.insertAd(mHotEffectDatas);
//                    if (isAllDataLoaded()) {
//                        refreshDatas();
//                    }
//                }
//
//                @Override
//                public void onAdLoadFailure(String err) {
//
//                }
//
//                @Override
//                public void onAdClicked(String cacheKey) {
//                }
//
//                @Override
//                public void onAdImpression(String cacheKey) {
//
//                }
//            });
//        }
//        mAdProvider.loadAd(getActivity());
    }

    private void destoryFlowAd() {
//        for (MultiItemEntity itemBean : mHotEffectDatas) {
//            if (itemBean instanceof AdItemBean) {
//                ((AdItemBean) itemBean).destory();
//            }
//        }
//
//        if (mAdProvider != null) {
//            mAdProvider.setAdListener(null);
//            mAdProvider.destroy();
//            mAdProvider = null;
//        }
    }

    private void checkAdValid() {
//        if ((mAdProvider != null && mAdProvider.checkAdValid(mHotEffectDatas))
//                && isAllDataLoaded()) {
//            refreshDatas();
//        }
    }


    /**
     * 处理下载Pip或者Filter
     *
     * @param storeOnlineBean
     * @param type
     */
    protected void downloadResource(final StoreOnlineBean storeOnlineBean, final int type) {
        DownloadUtils.getInstance().startDownload(storeOnlineBean, type);
    }

//    public void setActivity(HomeActivity entranceActivity) {
//        mEntranceActivity = entranceActivity;
//    }

    @OnClick({ R.id.img_menu, R.id.ivSetting,R.id.editor_tools_entrance})
    public void onEntranceClick(View v) {
        switch (v.getId()) {
            case R.id.editor_tools_entrance:
                SpUtils.obtain().save("isFunctionFilter", true);
                StatisticsUtils.statisticGrowingIo(StatisticsConstant.EVENT_MAIN_PAGE_CLICK,
                        StatisticsConstant.PROPERTY_KEY_IF_SUB, AppVipManager.isVip() ? StatisticsConstant.PROPERTY_VALUE_SUB : StatisticsConstant.PROPERTY_VALUE_UNSUB,
                        StatisticsConstant.KEY_MAIN_PAGE_FUN, StatisticsConstant.STATISTIC_EVENT_FUN_VALUE_EDIT);
                GalleryActivity.startGallerySelectEditImages(getContext(), "");
                break;
//            case R.id.llEffect:
//                GalleryActivity.startGallerySelectEditImages(getContext(), StatisticsConstant.MAIN_BTN_EFFECT);
//                SPDataManager.setFunctionEntrance(StatisticsConstant.MAIN_BTN_EFFECT);
//                StatisticsUtils.statisticGrowingIo(StatisticsConstant.EVENT_MAIN_PAGE_CLICK,
//                        StatisticsConstant.PROPERTY_KEY_IF_SUB, AppVipManager.isVip() ? StatisticsConstant.PROPERTY_VALUE_SUB : StatisticsConstant.PROPERTY_VALUE_UNSUB,
//                        StatisticsConstant.KEY_MAIN_PAGE_FUN, StatisticsConstant.MAIN_BTN_EFFECT);
//                break;
////            case R.id.tv_edit:
//            case R.id.llEdit:
//                GalleryActivity.startGallerySelectEditImages(getContext(), StatisticsConstant.MAIN_BTN_EDIT);
//                SPDataManager.setFunctionEntrance(StatisticsConstant.MAIN_BTN_EDIT);
//                StatisticsUtils.statisticGrowingIo(StatisticsConstant.EVENT_MAIN_PAGE_CLICK,
//                        StatisticsConstant.PROPERTY_KEY_IF_SUB, AppVipManager.isVip() ? StatisticsConstant.PROPERTY_VALUE_SUB : StatisticsConstant.PROPERTY_VALUE_UNSUB,
//                        StatisticsConstant.KEY_MAIN_PAGE_FUN, StatisticsConstant.MAIN_PAGE_VALUE_EDIT);
//                break;
//            case R.id.llAdjust:
//                GalleryActivity.startGallerySelectEditImages(getContext(), StatisticsConstant.MAIN_BTN_ADJUST);
//                SPDataManager.setFunctionEntrance(StatisticsConstant.MAIN_BTN_ADJUST);
//                StatisticsUtils.statisticGrowingIo(StatisticsConstant.EVENT_MAIN_PAGE_CLICK,
//                        StatisticsConstant.PROPERTY_KEY_IF_SUB, AppVipManager.isVip() ? StatisticsConstant.PROPERTY_VALUE_SUB : StatisticsConstant.PROPERTY_VALUE_UNSUB,
//                        StatisticsConstant.KEY_MAIN_PAGE_FUN, StatisticsConstant.MAIN_BTN_ADJUST);
//                break;

//            case R.id.tv_subscribe:
//                if (!AppVipManager.isVip()) {
//                    SVipController.showSubscribeActivity(getActivity(), SVipConstant.VIP_ENTRANCE_IN_APP, StatisticsConstant.ENTRANCE_VALUE_SUB_BOTTOM);
//                } else {
//                    GalleryActivity.startGallerySelectEditImagesToBeauty(getContext(), StatisticsConstant.MAIN_BTN_BEAUTY);
//                    SPDataManager.setFunctionEntrance(StatisticsConstant.MAIN_BTN_BEAUTY);
//                }
//                StatisticsUtils.statisticGrowingIo(StatisticsConstant.EVENT_MAIN_PAGE_CLICK,
//                        StatisticsConstant.PROPERTY_KEY_IF_SUB, AppVipManager.isVip() ? StatisticsConstant.PROPERTY_VALUE_SUB : StatisticsConstant.PROPERTY_VALUE_UNSUB,
//                        StatisticsConstant.KEY_MAIN_PAGE_FUN, StatisticsConstant.MAIN_PAGE_VALUE_PREMIUM);
//                break;
            case R.id.img_menu:
            case R.id.ivSetting:
                SettingActivity.startActivity(getContext());
                break;
            default:
                break;
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onSubscribeSuccessEvent(SubscribeSuccessEvent event) {
        if (mHotEffectAdapter != null) {
            mHotEffectAdapter.setVip(true);
            mHotEffectAdapter.notifyDataSetChanged();
        }
    }


}
